<template>
  <div>
    <div style="margin-bottom: 30px">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>留言管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <h1>留言列表</h1>
    <el-divider></el-divider>
    <el-card class="box-card" v-for="message in messages" shadow="hover">
      <div>
        <span>{{ message.theme }}</span>
        <el-button type="success" style="margin-left: 100px" @click="edit(message)" class="mr-5">查看
          <i class="el-icon-edit"></i></el-button>
        <el-popconfirm
            confirm-button-text='确定'
            cancel-button-text='再想想'
            icon="el-icon-info"
            icon-color="red"
            title="确定删除吗？"
            @confirm="del(message.messageId)">
          <el-button type="danger" slot="reference">删除<i class="el-icon-delete"></i></el-button>
        </el-popconfirm>
        <br>
        <span style="font-size: 12px">留言时间：{{ message.time }}</span>
      </div>
    </el-card>
    <el-dialog
        title="留言信息"
        :visible.sync="dialogVisible"
        width="40%">
        <el-descriptions :column="2" title="">
          <el-descriptions-item label="手机号" >{{message.telephone}}</el-descriptions-item>
          <el-descriptions-item label="机构">{{ message.mechanism }}</el-descriptions-item>
          <el-descriptions-item label="邮箱">{{ message.mail }}</el-descriptions-item>
          <el-descriptions-item label="主题">{{message.theme}}</el-descriptions-item>
        </el-descriptions>
      <h3 class="mb-5" style="margin:20px 0;">留言内容</h3>
      <p v-html="message.text" style="padding: 10px;border: #d3dce6 solid 2px;border-radius: 5px">
<!--        {{message.text}}-->
      </p>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Msgmanger",
  data() {
    return {
      messages: [],
      message: {},
      dialogVisible:false,
      btnText:'',
      rules:{}
    }
  },
  created() {
    this.load()
  },
  methods:{
    load() {
      request.get("/onlineMessage/getAll").then(res => {
        this.messages = res.data.records
      })
    },
    edit(message){
      this.message=Object.assign({},message)
      this.dialogVisible=true
      this.btnText='修改'
    },
    del(id){
      request.delete("onlineMessage/delmore/" + id).then(res => {
        if (res.code === 200) {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
    },

  }
}
</script>

<style scoped>
.box-card {
  margin: 20px auto;
  width: 80%;
  height: 100px;
  font-size: 20px;
}
</style>